<?php
/**
 *	KLF Framework
 *
 *	Written by Kristian Oye <kristianoye@gmail.com> on Nov 20, 2011
 *	Copyright (C) 2010-2011
 */
namespace KLF\System\Errors
{
	/**
	 *  Class KConnectionException
	 *
	 *  Error gets thrown when a connection fails or times out.
	 *
	 *  @package KLF\System\Errors
	 *  @access public
	 *  @author Kristian Oye <kristianoye@gmail.com>
	 *  @since 0.1
	 *
	 *  @method KConnectionException NewInstance
	 */
	use KLF\KCore;

	class KConnectionException extends KException
	{
		public function __construct($host,$port=0,$protocol='TCP',$serviceName='',$errorType='timed out')
		{
			if (strlen($serviceName) > 0)
			{
				parent::__construct(KCore::FS("Connection to service '{service}' at {protocol}://{host}{port} {error}", 
					array(
						'service' => $serviceName,
						'protocol' => $protocol,
						'host' => $host,
						'port' => ($port > 0 ? ":$port" : ''),
						'error' => $errorType )));
			}
			else
			{
				parent::__construct(KCore::FS("Connection to {protocol}://{host}{port} {error}", 
					array(
						'protocol' => $protocol,
						'host' => $host,
						'port' => ($port > 0 ? ":$port" : ''),
						'error' => $errorType )));
			}
		}
	}
}
